package com.bojx.report.dao;

import java.util.List;

import com.jfinal.kit.Kv;
import com.jfinal.plugin.activerecord.Db;
import com.jfinal.plugin.activerecord.Record;
import com.jfinal.plugin.activerecord.SqlPara;

public class BasicDataDao {

	public void batchSaveBranchData(List<Record> list) {
		Db.batchSave("report_bank_branch_data", list, 5);
	}
	public void saveUploadedExcel(Record e) {
		Db.save("report_uploaded_excel",e);
	}
	public void batchSaveClientData(List<Record> list) {
		Db.batchSave("report_client_data", list, 5);
	}

	public void batchSaveBusinessData(List<Record> list) {
		Db.batchSave("report_business_data", list, 50);
	}

	public List<Record> findAreas() {
		String sql = Db.getSql("excel.getAllAreas");
		return Db.find(sql);
	}

	public Record findBankBranchInfo(int year, int month, String area) {
		Kv cond = Kv.by("year", year).set("month", month).set("area", area);
		SqlPara sqlPara = Db.getSqlPara("excel.getBankBranchByArea", cond);
		return Db.findFirst(sqlPara);
	}

	public Record findClientInfo(int year, int month, String area) {
		Kv cond = Kv.by("year", year).set("month", month).set("area", area);
		SqlPara sqlPara = Db.getSqlPara("excel.findClientInfo", cond);
		return Db.findFirst(sqlPara);
	}

	public Record findBusinessData(int year, int month, String area, String billType, String statisticsType,
			String actionType) {
		Kv cond = Kv.by("year", year).set("month", month).set("area", area).set("billType", billType)
				.set("statisticsType", statisticsType).set("actionType", actionType);
		SqlPara sqlPara = Db.getSqlPara("excel.findBusinessData", cond);
		return Db.findFirst(sqlPara);
	}

	public List<Record> findBanks() {
		String sql = Db.getSql("excel.findBanks");
		return Db.find(sql);
	}

	public Record findBankBranchInfoByName(int year, int month, String organization) {
		Kv cond = Kv.by("year", year).set("month", month).set("organization", organization);
		SqlPara sqlPara = Db.getSqlPara("excel.getBankBranchByName", cond);
		return Db.findFirst(sqlPara);
	}

	public Record findClientInfoByName(int year, int month, String organization) {
		Kv cond = Kv.by("year", year).set("month", month).set("organization", organization);
		SqlPara sqlPara = Db.getSqlPara("excel.findClientInfoByName", cond);
		return Db.findFirst(sqlPara);
	}

	public Record findAgriBankBranchInfo(int year, int month) {
		Kv cond = Kv.by("year", year).set("month", month);
		SqlPara sqlPara = Db.getSqlPara("excel.findAgriBankBranchInfo", cond);
		return Db.findFirst(sqlPara);
	}

	public Record findArgiClientInfo(int year, int month) {
		Kv cond = Kv.by("year", year).set("month", month);
		SqlPara sqlPara = Db.getSqlPara("excel.findArgiClientInfo", cond);
		return Db.findFirst(sqlPara);
	}

	public Record findRuralBankBranchInfo(int year, int month) {
		Kv cond = Kv.by("year", year).set("month", month);
		SqlPara sqlPara = Db.getSqlPara("excel.findRuralBankBranchInfo", cond);
		return Db.findFirst(sqlPara);
	}

	public Record findRuralClientInfo(int year, int month) {
		Kv cond = Kv.by("year", year).set("month", month);
		SqlPara sqlPara = Db.getSqlPara("excel.findRuralClientInfo", cond);
		return Db.findFirst(sqlPara);
	}

	public Record findBusinessDataByBankName(int year, int month, String bankName, String billType, String statisticsType,String actionType) {
		Kv cond=Kv.by("year", year).set("month", month).set("organization", bankName).set("billType",billType).set("statisticsType",statisticsType).set("actionType",actionType);
	    SqlPara sqlPara=Db.getSqlPara("excel.findBusinessDataByBankName",cond);
	    return Db.findFirst(sqlPara);
	}

	public Record findBusinessDataByClassify(int year, int month, String classify, String billType, String statisticsType,String actionType) {
		Kv cond=Kv.by("year", year).set("month", month).set("classify", classify).set("billType",billType).set("statisticsType",statisticsType).set("actionType",actionType);
	    SqlPara sqlPara=Db.getSqlPara("excel.findBusinessDataByClassify",cond);
	    return Db.findFirst(sqlPara);
	}

	public Record findBankBranchQuarterInfo(int year, int quarter, String area) {
		Kv cond = Kv.by("year", year).set("quarter", quarter).set("area", area);
		SqlPara sqlPara = Db.getSqlPara("excel.getBankBranchQuarterByArea", cond);
		return Db.findFirst(sqlPara);
	}

	public Record findClientQuarterInfo(int year, int quarter, String area) {
		Kv cond = Kv.by("year", year).set("quarter", quarter).set("area", area);
		SqlPara sqlPara = Db.getSqlPara("excel.findClientQuarterInfo", cond);
		return Db.findFirst(sqlPara);
	}
	
	public Record findQuarterBusinessData(int year, int quarter, String area, String billType, String statisticsType,
			String actionType) {
		Kv cond = Kv.by("year", year).set("quarter", quarter).set("area", area).set("billType", billType)
				.set("statisticsType", statisticsType).set("actionType", actionType);
		SqlPara sqlPara = Db.getSqlPara("excel.findQuarterBusinessData", cond);
		return Db.findFirst(sqlPara);
	}

	public Record findBankBranchQuarterInfoByName(int year, int quarter, String organization) {
		Kv cond = Kv.by("year", year).set("quarter", quarter).set("organization", organization);
		SqlPara sqlPara = Db.getSqlPara("excel.getBankBranchQuarterByName", cond);
		return Db.findFirst(sqlPara);
	}

	public Record findClientQuarterInfoByName(int year, int quarter, String bankName) {
		Kv cond = Kv.by("year", year).set("quarter", quarter).set("organization", bankName);
		SqlPara sqlPara = Db.getSqlPara("excel.findClientQuarterInfoByName", cond);
		return Db.findFirst(sqlPara);
	}

	public Record findAgriBankBranchQuarterInfo(int year, int quarter) {
		Kv cond = Kv.by("year", year).set("quarter", quarter);
		SqlPara sqlPara = Db.getSqlPara("excel.findAgriBankBranchQuarterInfo", cond);
		return Db.findFirst(sqlPara);
	}

	public Record findArgiClientQuarterInfo(int year, int quarter) {
		Kv cond = Kv.by("year", year).set("quarter", quarter);
		SqlPara sqlPara = Db.getSqlPara("excel.findArgiClientQuarterInfo", cond);
		return Db.findFirst(sqlPara);
	}

	public Record findRuralBankBranchQuarterInfo(int year, int quarter) {
		Kv cond = Kv.by("year", year).set("quarter", quarter);
		SqlPara sqlPara = Db.getSqlPara("excel.findRuralBankBranchQuarterInfo", cond);
		return Db.findFirst(sqlPara);
	}
	
	public Record findRuralClientQuarterInfo(int year, int quarter) {
		Kv cond = Kv.by("year", year).set("quarter", quarter);
		SqlPara sqlPara = Db.getSqlPara("excel.findRuralClientQuarterInfo", cond);
		return Db.findFirst(sqlPara);
	}

	public Record findQuarterBusinessDataByBankName(int year, int quarter, String bankName, String billType,
			String statisticsType, String actionType) {
		Kv cond=Kv.by("year", year).set("quarter", quarter).set("organization", bankName).set("billType",billType).set("statisticsType",statisticsType).set("actionType",actionType);
	    SqlPara sqlPara=Db.getSqlPara("excel.findQuarterBusinessDataByBankName",cond);
	    return Db.findFirst(sqlPara);
	}

	public Record findQuarterBusinessDataByClassify(int year, int quarter, String classify, String billType,
			String statisticsType, String actionType) {
		Kv cond=Kv.by("year", year).set("quarter", quarter).set("classify", classify).set("billType",billType).set("statisticsType",statisticsType).set("actionType",actionType);
	    SqlPara sqlPara=Db.getSqlPara("excel.findQuarterBusinessDataByClassify",cond);
	    return Db.findFirst(sqlPara);
	}


}
